package cn.fufeiii.bt.nomiddleware.codec;


import cn.fufeiii.bt.common.util.RsaUtil;

import java.util.Base64;

/**
 * 原生API进行RSA的加解密
 *
 * @author FuFei
 */
public class RsaMain {
    public static String bizPriKey = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAMt7Tc4HdlfYnGDtsMfiABK1hyc8SxZRDqUqEs9jBqB/C02Th7gXSWN3O51SZhslPI0dCFtV4TvnbXWhwYpRrBbkw+9nrG1Whz/13UN+1vBYDvjEUorgEn+7fV4YWQo8OHtjTwY2bbSzrtw2pW6crqXGYbJU7KPGT8Kiu67VUtvFAgMBAAECgYAIMm3ovXeAn29zjG+zl+50ZMYXrL/CdywsgLN2kbMptrbAEOtzgdLtzTJSGFG80hCMdUtOYzAO0KXGZfqvLGmFvGn5sRCpYtlzEndcJUW21lPvMHJ9YdSxlcLQCfCHq0pyjqkVwQCYPoApp1AXgTGtNthTWMD0Ah2d87yctv0AywJBAPcFDELzi2BDbBvCmgsi9j6Fm2IhNEcgCbmToTKJu3xeboxGGop5u1Ulko874eQvdQoCK8ozaTvn/f2ceRL+lXsCQQDS4Q7UgpCnbQZ/azeERTH/R9kXJMUWijHkesdKTzs1CDbbmWqwqebomUW3HjI+VBVjlsj9xEV4cMB2PvboY2+/AkEA7uO+2/DUVaBeqOomN6b0JbrobppWCIL/ZK1VM57n5nscxiP1/v2DIfFYL5Vl/Fu5AJjg6IeXugu+Isp0fN4giQJBALLhBdtuBZZ//QsIv8cLiyWopJXlMumzwC63l2WJYAfUN/R/ZukEtkKIAYMbsjL80EfyF/xrCSLpQdkMABWQg7ECQQCW3Q9zwKKd//mVyKPvJ/vkbqns60jqxcoXkOebgkTkZNyR6fjDlaJrbaUC50AMlgkQVVXTVGRb0KSiSTwikpXo";
    public static String bizPubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLe03OB3ZX2Jxg7bDH4gAStYcnPEsWUQ6lKhLPYwagfwtNk4e4F0ljdzudUmYbJTyNHQhbVeE75211ocGKUawW5MPvZ6xtVoc/9d1DftbwWA74xFKK4BJ/u31eGFkKPDh7Y08GNm20s67cNqVunK6lxmGyVOyjxk/Coruu1VLbxQIDAQAB";


    public static void main(String[] args) {
        String requestBody = "我是一个内容我是一个内容我是一个内容我是一个内容我是一个内容我是一个内容我是一个内容我是一个内容我是一个我是一个内容我是一个内容我是一个内容我是一个内容我是一个内容我是一个内容我是一个内容我是一个内容我是一个";

        // 加签
        byte[] signature = RsaUtil.signature(requestBody, bizPriKey);
        String signatureBase64 = new String(Base64.getEncoder().encode(signature));
        System.out.println(signatureBase64);
        // 验签
        boolean verify = RsaUtil.verify(requestBody, signatureBase64, bizPubKey);
        System.out.println("verify = " + verify);

        // 加密
        byte[] encrypt = RsaUtil.encrypt(requestBody, bizPriKey);
        String encryptBase64 = new String(Base64.getEncoder().encode(encrypt));
        System.out.println("encryptBase64 = " + encryptBase64);
        // 解密
        byte[] decrypt = RsaUtil.decrypt(encryptBase64, bizPubKey);
        String decryptBase64 = new String(decrypt);
        System.out.println("decryptBase64 = " + decryptBase64);

    }


}
